﻿namespace cbooc

import System
import Boo.Lang.Compiler
import Boo.Lang.Compiler.IO

def SetUpPipeline(cmdLine as CommandLine):
	if cmdLine.Benchmark:
		p = Pipelines.ResolveExpressions()
	else:
		p = Pipelines.CompileToFile()
		
	if not cmdLine.Concurrent:
		return p
	ConcurrentParsingStep.SetUp(p)
	return p
		
cmdLine = CommandLine(argv)
if not cmdLine.IsValid:
	cmdLine.PrintOptions()
	return

compiler = BooCompiler()
input = compiler.Parameters.Input
for src in cmdLine.Sources:
	input.Add(FileInput(src))
references = compiler.Parameters.References
for reference in cmdLine.References:
	references.Add(compiler.Parameters.LoadAssembly(reference))
	
compiler.Parameters.OutputType = cmdLine.Target
compiler.Parameters.Pipeline = SetUpPipeline(cmdLine)
compiler.Parameters.OutputAssembly = cmdLine.Output

start = date.Now
if cmdLine.Benchmark:
	times = 100
	print "Benchmarking compiler ${times} times."
	for i in range(times):
		result = compiler.Run()
else:
	result = compiler.Run()
	
print "Concurrent steps: ${cmdLine.Concurrent}"
print "Elapsed time: ${date.Now - start}"
print result.Errors.ToString()
